﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Adams.Admin.Presentation.Controllers
{
    [Authorize]
    [EnsureSsl]
    public class EventsController : Controller
    {
        [AppendLayoutViewModel]
        public ActionResult Index()
        {
            
            var model = Business.Events.Index.PageLoad();
            ViewBag.Message = Request["msg"];
            return View(model);
        }

        [AppendLayoutViewModel]
        public ActionResult CreateEvent(int id)
        {
            
            ViewBag.Start = Request["start"];
            ViewBag.End = Request["end"];
            ViewBag.IsAllDay = Request["allday"].ToBool();
            ViewBag.EventTitle = Request["title"];
            var model = Business.Events.CreateEvent.PageLoad(id);
            return View(model);
        }

        public JsonResult SaveEvent(Adams.Admin.DataTransfer.Events.CreateEvent.FormInput input)
        {
            var model = Business.Events.CreateEvent.SaveEvent(input);
            return Json(model);
        }

        public JsonResult DeleteEvent(Adams.Admin.DataTransfer.Events.CreateEvent.DeleteInput input)
        {
            Business.Events.CreateEvent.DeleteEvent(input);
            return Json(new { Status = "success" });
        }

        public JsonResult GetEvents(Adams.Admin.DataTransfer.Events.Index.GetEventsInput input)
        {
            var model = Business.Events.Index.GetEvents(input);
            return Json(model);
        }

        public JsonResult MoveEvent(Adams.Admin.DataTransfer.Events.Index.EventMoveInput input)
        {
            Business.Events.Index.MoveEvent(input);
            return Json(new { Status = "success" });
        }

        public JsonResult ResizeEvent(Adams.Admin.DataTransfer.Events.Index.EventResizeInput input)
        {
            Business.Events.Index.ResizeEvent(input);
            return Json(new { Status = "success" });
        }

        [AppendLayoutViewModel]
        public ActionResult Calendars()
        {
            
            var model = Business.Events.Calendars.PageLoad();
            ViewBag.Message = Request["msg"];
            return View(model);
        }

        [AppendLayoutViewModel]
        public ActionResult CreateCalendar(int id)
        {
            
            var model = Business.Events.CreateCalendar.PageLoad(id);
            return View(model);
        }

        public JsonResult SaveCalendar(Adams.Admin.DataTransfer.Events.CreateCalendar.FormInput input)
        {
            var model = Business.Events.CreateCalendar.SaveCalendar(input);
            return Json(model);
        }

        public RedirectResult DeleteCalendar(int id)
        {
            Business.Events.Calendars.Delete(id);
            var model = new { Deleted = true };
            return Redirect("/Events/Calendars?msg=2");
        }
    }
}
